const formRules = require("../util/formRules.js");
module.exports = {
	/**
	 * 修改
	 * @url admin/person/sys/update 前端调用的url参数地址
	 * data 请求参数 说明
	 * @param {String} name				姓名
	 * @param {String} job				职业
	 * @param {String} field			领域
	 * @param {String} images			照片
	 * @param {String} summary			摘要
	 * @param {String} mode				内容展示模式 editor-富文本 pdf-PDF文件 video-视频
	 * @param {String} content			正文
	 * @param {String} file				pdf文件路径、视频文件路径
	 * @param {String} nav_id			栏目id
	 * @param {Boolean} enable			是否启用
	 * res 返回参数说明
	 * @param {Number} code 错误码，0表示成功
	 * @param {String} msg 详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		let {
			_id,
			name,
			job,
			field,
			images,
			summary,
			mode,
			content,
			file,
			nav_id,
			enable = true
		} = data;
		// 参数合法校验开始-----------------------------------------------------------
		let formRulesRes = await formRules.update(event);
		if (formRulesRes.code !== 0) {
			return formRulesRes;
		}
		// 参数合法校验结束-----------------------------------------------------------
		let dbName = "lzy-person";
		
		let now = new Date().getTime();
		let dataJson = {
			name,
			job,
			field,
			images,
			summary,
			mode,
			content,
			file,
			nav_id,
			enable,
			publish_time: now,
			publish_time_str: vk.pubfn.timeFormat(now, "yyyy-MM-dd hh:mm:ss"),
			_edit_time: now,
			_edit_time_str: vk.pubfn.timeFormat(now, "yyyy-MM-dd hh:mm:ss"),
			_edit_user: uid,
			_edit_user_name: userInfo.username,
		};
		
		// 执行数据库API请求
		res.num = await vk.baseDao.updateById({
			dbName,
			id: _id,
			dataJson
		});
		return res;
	}
}